package com.dpiinc.TechPage.activity

import android.os.Bundle
import com.dpiinc.TechPage.AWLog
import com.dpiinc.TechPage.BaseActivity
import com.dpiinc.TechPage.R
import com.dpiinc.TechPage.UserManager
import com.dpiinc.TechPage.api.RetrofitFactory
import com.dpiinc.TechPage.api.asyncSubscribe
import com.dpiinc.TechPage.room.RoomAiWriterDatabase
import com.dpiinc.TechPage.utils.DateUtils
import kotlinx.android.synthetic.main.activity_test_api.*

class TestApiActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test_api)
        setSupportActionBar(toolbar)

        fab.setOnClickListener { _ ->
            //            addNewNote()
//            getNoteList()
            RoomAiWriterDatabase.getInstance(application).noteDao().deleteAll()
        }
    }

    private fun getNoteList() {
        val params = HashMap<String, String>()
        params["uId"] = UserManager.getUserId()
        params["accessToken"] = UserManager.getAccessToken()
        params["number"] = "20"
        params["listType"] = "0"
//        params["filterContent"] = ""
        params["page"] = "1"
//        params["latestGetTime"] = "",
        RetrofitFactory.getInstance().getNoteList(params)
                .doFinally {
                    AWLog.e("doFinally")
                }
                .asyncSubscribe({
                    AWLog.e(it.toString())
                }, {
                    AWLog.e(it.toString())
                })
//        RetrofitFactory.getInstance().getNoteList(UserManager.getUserId(), UserManager.getAccessToken(), 20, 0, "", 1, "0")
//                .doFinally {
//                    AWLog.e("doFinally")
//                }
//                .asyncSubscribe({
//                    AWLog.e(it.toString())
//                }, {
//                    AWLog.e(it.toString())
//                })
    }

    private fun addNewNote() {
        val params = HashMap<String, String>()
        params["uId"] = UserManager.getUserId()
        params["accessToken"] = UserManager.getAccessToken()
        params["noteOperate"] = "0"
//        params["noteId"] = noteId,
//        params["noteList"] = noteList,
//        params["noteName"] = noteName,
        params["createTime"] = DateUtils.getCurrentTimeMillis().toString()
//        params["editTime"] = editTime,
//        params["labList"] = labList
        RetrofitFactory.getInstance().editNote(params)
                .doFinally {
                    AWLog.e("doFinally")
                }
                .asyncSubscribe({
                    AWLog.e(it.toString())
                }, {
                    AWLog.e(it.toString())
                })
    }

}
